//
//  TKL_HomeCityDetailVC.m
//  TKL_EnPro
//
//  Created by 雅恩三河科技 on 2018/12/20.
//  Copyright © 2018年 MrZhang. All rights reserved.
//

//
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                  \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
//
//

#import "TKL_HomeCityDetailVC.h"
#import "RatingBar.h"
#import "TKL_AuthDetailVC.h"
@interface TKL_HomeCityDetailVC ()<SDCycleScrollViewDelegate>
@property(nonatomic,strong)NSMutableDictionary* dataSource;

@end

@implementation TKL_HomeCityDetailVC
#pragma mark - getter and setter
-(NSMutableDictionary *)dataSource
{
    if (!_dataSource) {
        _dataSource=[NSMutableDictionary new];
    }
    return _dataSource;
}
#pragma mark - event
#pragma mark - method
-(void)initilization
{
    self.isGroup=YES;
    [self setNavgationTheme:2];
    self.navigationItem.title = @"";
    self.extendedLayoutIncludesOpaqueBars = YES;
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    [self.view addSubview:self.baseTable];
    
    self.baseTable.contentInset = UIEdgeInsetsMake(-1, 0, [self bottomShelterHeight], 0);
    [self.baseTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.baseTable setSeparatorColor: Main_Color_BG];
    [self.baseTable setBackgroundColor:Main_Color_BG];
    [self.baseTable setTintColor:Main_Color_BG];
    @WeakSelf;
        [self viewModelBand];
   [self reloadData];
}
-(void)viewModelBand
{
    @WeakSelf;
}
-(void)reloadData
{
     [self requestCityData];
}
#pragma mark - life
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
   //
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initilization];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
#pragma mark - delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section==0) {
        return 2;
    }
    if (section==1) {
        return 1;
    }
    
    return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.section==0)
    {
        
        if (indexPath.row==1)
        {
            static NSString *CellID = @"CellID000011";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
            if (cell == nil) {
                cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            [cell.contentView removeAllSubviews];
            
            UILabel* titleLab=[UILabel new];
            titleLab.x=WFCGFloatX(10);
            titleLab.y=WFCGFloatY(15);
            titleLab.width=SCREEN_WIDTH-WFCGFloatX(20);
            titleLab.font=SYSTEMFONT(15);
            titleLab.textColor=HEXCOLOR(@"#333333");
            [cell.contentView addSubview:titleLab];
            titleLab.text=[WFFunctions WFCheckEmptyBackStr:[self.dataSource objectForKey:@"description"]];
            titleLab.numberOfLines=0;
            CGSize temSize=[WFFunctions WFStrGetSize:titleLab.text width:titleLab.width font:SYSTEMFONT(15)];
            titleLab.height=temSize.height;
            
            
            NSArray* arrr=@[@"美食",@"消费",@"风景",@"休闲"];
            
            for (int i=0; i<4; i++)
            {
                RatingBar *star = [[RatingBar alloc] initWithFrame:CGRectMake(WFCGFloatX(50)+(SCREEN_WIDTH/2)*(i%2), WFCGFloatY(30)+temSize.height+(i/2)*30, 100, 16)];
                star.enable = NO;
                star.starNumber = 3;
                if (i==0) {
                    star.starNumber=[[self.dataSource objectForKey:@"foodScore"] floatValue];
                }
                if (i==1) {
                    star.starNumber=[[self.dataSource objectForKey:@"shoppingScore"] floatValue];
                }
                if (i==2) {
                    star.starNumber=[[self.dataSource objectForKey:@"scenicScore"] floatValue];
                }
                if (i==3) {
                    star.starNumber=[[self.dataSource objectForKey:@"leisureScore"] floatValue];
                }
                [cell.contentView addSubview:star];
                
                UILabel* detailLab=[[UILabel alloc] init];
                detailLab.textAlignment = NSTextAlignmentLeft;
                detailLab.text = arrr[i];
                detailLab.font = SYSTEMFONT(14);
                detailLab.textColor = HEXCOLOR(@"#333333");
                detailLab.x=WFCGFloatX(10)+(SCREEN_WIDTH/2)*(i%2);
                detailLab.y=WFCGFloatY(30)+temSize.height+(i/2)*30;
                detailLab.width=WFCGFloatX(40);
                detailLab.height=WFCGFloatY(15);
                [cell.contentView addSubview:detailLab];
            }
            
            return cell;
        }
        
        static NSString *CellID = @"CellID111";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        [cell.contentView removeAllSubviews];
        SDCycleScrollView* bannerScroll=[SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, WFCGFloatX(375), WFCGFloatY(190)) delegate:self placeholderImage:DefaultImage];
        bannerScroll.backgroundColor=Main_Color_BGLightGray;
        bannerScroll.currentPageDotColor=Main_Color_Gold;
        bannerScroll.pageDotColor=[UIColor whiteColor];
        bannerScroll.showPageControl=NO;
        bannerScroll.pageControlBottomOffset=5;
        [cell.contentView addSubview:bannerScroll];
        NSMutableArray* imageArr=[[NSMutableArray alloc] init];
        NSArray* arr=[self.dataSource objectForKey:@"guestWorks"];
        if (arr) {
            NSArray* iamgeArr=[arr[0] objectForKey:@"images"];
            for (NSDictionary* model in iamgeArr)
            {
                [imageArr addObject:[model objectForKey:@"url"]];
            }
            bannerScroll.imageURLStringsGroup=imageArr;
        }
        return cell;
    }
    if (indexPath.section==1)
    {
        static NSString *CellID = @"CellIDppppppp";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
        }
        [cell.contentView removeAllSubviews];
        
        NSArray* arr=[self.dataSource objectForKey:@"tripTeams"];
        
        float ww=(SCREEN_WIDTH-WFCGFloatX(300))/3;
        for (int i=0; i<4; i++)
        {
            NSDictionary* dic=[arr objectAtIndex:i];
            UIView* view=[UIView new];
            view.x=ww+(ww+WFCGFloatX(150))*(i%2);
            view.y=(ww+WFCGFloatX(150))*(i/2);
            view.width=WFCGFloatX(150);
            view.height=view.width;
            view.backgroundColor=[UIColor whiteColor];
            [cell.contentView addSubview:view];
            [WFFunctions WFUIaddbordertoView:view radius:0 width:0.5 color:YN_Main_Line_BG];
            
            [view addTapGestureRecognizerWithDelegate:self Block:^(NSInteger tag) {
                NSLog(@"-----点击作者");
                TKL_AuthDetailVC* vc=[[TKL_AuthDetailVC alloc] init];
                vc.passID=[NSString stringWithFormat:@"%@",[dic objectForKey:@"id"]];
                [self.navigationController pushViewController:vc animated:YES];
            }];
            
            UIImageView* headIV=[UIImageView new];
            headIV.x=0;
            headIV.y=0;
            headIV.width=view.width;
            headIV.height=view.height/2;
            [headIV sd_setImageWithURL:[dic objectForKey:@"coverImgFileName4Works"] placeholderImage:DefaultImage];
            
            [view addSubview:headIV];
            
            
            UIImageView* markIV=[UIImageView new];
            markIV.x=view.height/2-WFCGFloatX(20);
            markIV.y=view.height/2-WFCGFloatX(20);
            markIV.width=WFCGFloatX(40);
            markIV.height=markIV.width;
            [markIV sd_setImageWithURL:[[dic objectForKey:@"photographer"] objectForKey:@"headImgFileName"] placeholderImage:DefaultImage];
            [view addSubview:markIV];
            [WFFunctions WFUIaddbordertoView:markIV radius:WFCGFloatX(20) width:3 color:[UIColor whiteColor]];
            
            
            
            UILabel* titleLab=[UILabel new];
            titleLab.x=WFCGFloatX(0);
            titleLab.y=headIV.height+WFCGFloatX(30);
            titleLab.width=view.width;
            titleLab.font=SYSTEMFONT(15);
            titleLab.textColor=HEXCOLOR(@"#333333");
            [view addSubview:titleLab];
            titleLab.height=WFCGFloatX(15);
            titleLab.textAlignment=NSTextAlignmentCenter;
            titleLab.text=[[dic objectForKey:@"photographer"] objectForKey:@"name"];
            
            UILabel* titleLab1=[UILabel new];
            titleLab1.x=WFCGFloatX(0);
            titleLab1.y=headIV.height+WFCGFloatX(50);
            titleLab1.width=view.width;
            titleLab1.font=SYSTEMFONT(13);
            titleLab1.textColor=HEXCOLOR(@"#666666");
            titleLab1.text=[NSString stringWithFormat:@"预约%@ 好评%@",[dic objectForKey:@"orderCount"],[dic objectForKey:@"commentCount"]];
            [view addSubview:titleLab1];
            titleLab1.height=WFCGFloatX(15);
            titleLab1.textAlignment=NSTextAlignmentCenter;
        }
        
        return cell;
    }
    if (indexPath.row==3)
    {
        static NSString *CellID = @"CellIDpwwfff";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        [cell.contentView removeAllSubviews];
        NSDictionary* dic=[self.dataSource objectForKey:@"experienceStore"];
        NSArray* arr=[dic objectForKey:@"images"];
        UIScrollView* screoll=[[UIScrollView alloc] init];
        screoll.x=0;
        screoll.y=0;
        screoll.width=SCREEN_WIDTH;
        screoll.height=WFCGFloatY(100);
        screoll.showsVerticalScrollIndicator=NO;
        screoll.showsHorizontalScrollIndicator=NO;
        screoll.contentSize=CGSizeMake(arr.count/2*SCREEN_WIDTH, WFCGFloatY(100));
        [cell.contentView addSubview:screoll];
        [screoll removeAllSubviews];
        for (int i=0; i<arr.count; i++)
        {
            NSDictionary* hhhh=[arr objectAtIndex:i];
            UIImageView* iamgeVIew=[[UIImageView alloc] init];
            iamgeVIew.x=WFCGFloatX(10)+WFCGFloatY(170)*i;
            iamgeVIew.y=0;
            iamgeVIew.width=WFCGFloatX(160);
            iamgeVIew.height=WFCGFloatY(100);
            [screoll addSubview:iamgeVIew];
            NSString *imgUrl = [[hhhh objectForKey:@"url"]  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [iamgeVIew sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:DefaultImage];
            __block UIImageView* pppImage=iamgeVIew;
            [iamgeVIew addTapGestureRecognizerWithDelegate:self Block:^(NSInteger tag) {
                PYPhotoBrowseView *photoBroseView = [[PYPhotoBrowseView alloc] init];
                photoBroseView.imagesURL = @[imgUrl];
                photoBroseView.currentIndex = 0;
                photoBroseView.sourceImgageViews=@[pppImage];
                [photoBroseView show];
            }];
        }
        return cell;
    }
    static NSString *CellID = @"CellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    NSDictionary* dic=[self.dataSource objectForKey:@"experienceStore"];
    cell.textLabel.textColor=HEXCOLOR(@"#333333");
    cell.textLabel.font=SYSTEMFONT(15);
    if (indexPath.row==0)
    {
        cell.textLabel.text=[NSString stringWithFormat:@"门店地址:%@",[dic objectForKey:@"address"]];
    }
    if (indexPath.row==1)
    {
        cell.textLabel.text=[NSString stringWithFormat:@"营业时间:%@",[dic objectForKey:@"workTime"]];
    }
    if (indexPath.row==2)
    {
        cell.textLabel.text=[NSString stringWithFormat:@"联系方式:%@",@"4006808333"];
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0)
    {
        if (indexPath.row==0) {
            return WFCGFloatY(190);
        }
        CGSize temSize=[WFFunctions WFStrGetSize:[WFFunctions WFCheckEmptyBackStr:[self.dataSource objectForKey:@"description"]] width:SCREEN_WIDTH-WFCGFloatX(20) font:SYSTEMFONT(15)];
        return temSize.height+WFCGFloatY(90);
    }
    if (indexPath.section==1) {
        return WFCGFloatY(330);
    }
    if (indexPath.row==3) {
        return WFCGFloatY(100);
    }
    return WFCGFloatY(40);
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=[UIColor whiteColor];
    if (section!=0)
    {
        UILabel* titleLab=[UILabel new];
        titleLab.x=WFCGFloatX(0);
        titleLab.y=WFCGFloatY(0);
        titleLab.width=SCREEN_WIDTH;
        titleLab.font=SYSTEMFONT(16);
        titleLab.textColor=HEXCOLOR(@"#333333");
        [view addSubview:titleLab];
        titleLab.text=section==1?@"人气摄影师":@"线下体验店";
        titleLab.height=WFCGFloatY(50);
        titleLab.textAlignment=NSTextAlignmentCenter;
        
    }
    return view;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=Main_Color_BG;
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0) {
        return .00001f;
    }
    return WFCGFloatY(50);
}
////http://101.201.171.131:8080/rest/api/user/detail/ 用户详情  userUuid=63e5eeec-588a-4c66-9356-ab7b4313a020
-(void)requestCityData
{
    @WeakSelf;
    NSMutableDictionary* para=[NSMutableDictionary new];
    //http://appserver.hunlimao.com/tripCity/14?device=iPhone&city=%E6%B5%8E%E5%8D%97&cid=53424&key=18765319560_HunLiMao_63afa4ddecb0478791a35471d5cd435f
    [para setObject:@"iPhone" forKey:@"device"];
    [para setObject:@"济南" forKey:@"city"];
    [para setObject:@"53424" forKey:@"cid"];
    //[para setObject:@"" forKey:@"key"];
    [para setObject:_passID forKey:@"id"];
    [[InterfaceManager shareInterface] requetInterface:@"get_city_detail" withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        if (infoModel.errorCode ==0)
        {
            [self.dataSource removeAllObjects];
            self.dataSource=[[NSMutableDictionary alloc] initWithDictionary: info];

            [selfp.baseTable reloadData];
        }else
        {
            [FTIndicator showErrorWithMessage:infoModel.errorMsg];
        }
    }];;
}
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    
    
//    NSArray* arr=[self.dataSource objectForKey:@"guestWorks"];
//    NSArray* iamgeArr=[arr[0] objectForKey:@"images"];
//    NSDictionary* dic=[iamgeArr objectAtIndex:index];
//
//    PYPhotoBrowseView *photoBroseView = [[PYPhotoBrowseView alloc] init];
//    photoBroseView.imagesURL = @[[dic objectForKey:@"url"]];
//    photoBroseView.currentIndex = 0;
//    //photoBroseView.sourceImgageViews=@[pp];
//    [photoBroseView show];

}
@end


/*
 11111111111111111111111111111111111111001111111111111111111111111
 11111111111111111111111111111111111100011111111111111111111111111
 11111111111111111111111111111111100001111111111111111111111111111
 11111111111111111111111111111110000111111111111111111111111111111
 11111111111111111111111111111000000111111111111111111111111111111
 11111111111111111111111111100000011110001100000000000000011111111
 11111111111111111100000000000000000000000000000000011111111111111
 11111111111111110111000000000000000000000000000011111111111111111
 11111111111111111111111000000000000000000000000000000000111111111
 11111111111111111110000000000000000000000000000000111111111111111
 11111111111111111100011100000000000000000000000000000111111111111
 11111111111111100000110000000000011000000000000000000011111111111
 11111111111111000000000000000100111100000000000001100000111111111
 11111111110000000000000000001110111110000000000000111000011111111
 11111111000000000000000000011111111100000000000000011110001111111
 11111110000000011111111111111111111100000000000000001111100111111
 11111111000001111111111111111111110000000000000000001111111111111
 11111111110111111111111111111100000000000000000000000111111111111
 11111111111111110000000000000000000000000000000000000111111111111
 11111111111111111100000000000000000000000000001100000111111111111
 11111111111111000000000000000000000000000000111100000111111111111
 11111111111000000000000000000000000000000001111110000111111111111
 11111111100000000000000000000000000000001111111110000111111111111
 11111110000000000000000000000000000000111111111110000111111111111
 11111100000000000000000001110000001111111111111110001111111111111
 11111000000000000000011111111111111111111111111110011111111111111
 11110000000000000001111111111111111100111111111111111111111111111
 11100000000000000011111111111111111111100001111111111111111111111
 11100000000001000111111111111111111111111000001111111111111111111
 11000000000001100111111111111111111111111110000000111111111111111
 11000000000000111011111111111100011111000011100000001111111111111
 11000000000000011111111111111111000111110000000000000011111111111
 11000000000000000011111111111111000000000000000000000000111111111
 11001000000000000000001111111110000000000000000000000000001111111
 11100110000000000001111111110000000000000000111000000000000111111
 11110110000000000000000000000000000000000111111111110000000011111
 11111110000000000000000000000000000000001111111111111100000001111
 11111110000010000000000000000001100000000111011111111110000001111
 11111111000111110000000000000111110000000000111111111110110000111
 11111110001111111100010000000001111100000111111111111111110000111
 11111110001111111111111110000000111111100000000111111111111000111
 11111111001111111111111111111000000111111111111111111111111100011
 11111111101111111111111111111110000111111111111111111111111001111
 11111111111111111111111111111110001111111111111111111111100111111
 11111111111111111111111111111111001111111111111111111111001111111
 11111111111111111111111111111111100111111111111111111111111111111
 11111111111111111111111111111111110111111111111111111111111111111
 
 
 */
